import mongoose from "mongoose";
import { dbUri } from "../config/config.default";

import { articleSchema } from "./article";
import { articleLogSchema } from "./articleLog";
import { userSchema } from "./user";
import { adminSchema } from "./admin";

mongoose.connect(dbUri, { useUnifiedTopology: true, useNewUrlParser: true });

const db = mongoose.connection;
db.on("error", () => console.info("mongodb 数据库连接失败"));
db.once("open", () => console.info("mongodb 数据库连接成功"));

const e = {
  User: mongoose.model("User", userSchema),
  Article: mongoose.model("Article", articleSchema),
  ArticleLog: mongoose.model("ArticleLog", articleLogSchema),
  Admin: mongoose.model("Admin", adminSchema)
};

export = e;
